#include "WObject.h"

#include "WRenderer.h"

std::vector<std::shared_ptr<WObject>> WObject::PreUpdateList;
std::vector<std::shared_ptr<WObject>> WObject::UpdateList;
std::vector<std::shared_ptr<WObject>> WObject::PreRenderList;


void WObject::RegisterPreUpdater(std::shared_ptr<WObject> updater)
{
	if(std::find(PreUpdateList.begin(), PreUpdateList.end(), updater) == PreUpdateList.end())
	{
		PreUpdateList.push_back(updater);
	}
}

void WObject::UnregisterPreUpdater(std::shared_ptr<WObject> updater)
{
	int index = (int) (std::find(PreUpdateList.begin(), PreUpdateList.end(), updater) - PreUpdateList.begin());
	if(index >= 0)
	{
		PreUpdateList.erase(PreUpdateList.begin() + index);
	}
}

void WObject::PreUpdateObjects()
{
	for(unsigned int i=0; i<PreUpdateList.size(); i++)
	{
		std::shared_ptr<WObject> obj = PreUpdateList.at(i);
		obj->PreUpdate();
	}
}

void WObject::RegisterUpdater(std::shared_ptr<WObject> updater)
{
	if(std::find(UpdateList.begin(), UpdateList.end(), updater) == UpdateList.end())
	{
		UpdateList.push_back(updater);
	}
}

void WObject::UnregisterUpdater(std::shared_ptr<WObject> updater)
{
	int index = (int) (std::find(UpdateList.begin(), UpdateList.end(), updater) - UpdateList.begin());
	if(index >= 0)
	{
		UpdateList.erase(UpdateList.begin() + index);
	}
}

void WObject::UpdateObjects(std::shared_ptr<WRenderer> renderer)
{
	for(unsigned int i=0; i<UpdateList.size(); i++)
	{
		std::shared_ptr<WObject> obj = UpdateList.at(i);
		obj->Update(renderer);
	}
}


void WObject::RegisterPreRenderObj(std::shared_ptr<WObject> obj)
{

}

void WObject::UnregisterPreRenderObj(std::shared_ptr<WObject> obj)
{

}

void WObject::PreRenderObjects()
{

}
	